package com.rabbit.eap.controller.system;

import com.rabbit.eap.framework.common.api.ApiResult;
import com.rabbit.eap.framework.log.annotation.Module;
import com.rabbit.eap.framework.log.annotation.OperationLogIgnore;
import com.rabbit.eap.system.param.LoginParam;
import com.rabbit.eap.system.service.LoginService;
import com.rabbit.eap.system.vo.LoginSysUserTokenVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * @projectName eap
 * @packageName com.rabbit.eap.controller.sys
 * @className LoginController
 * @author： rabbit
 * @version： 1.0
 * @since： 2020/4/30 16:49
 * <p>Description: LoginController
 * 登录控制器
 * </p>

 */
@Slf4j
@RestController
@Module("system")
@Api(value = "系统登录API", tags = {"系统登录"})
public class LoginController {
    @Autowired
    private LoginService loginService;

    @PostMapping("/login")
    @OperationLogIgnore
    @ApiOperation(value = "登录", notes = "系统用户登录", response = LoginSysUserTokenVO.class)
    public ApiResult<LoginSysUserTokenVO> login(@Validated @RequestBody LoginParam loginParam, HttpServletResponse response) throws Exception {
        ApiResult<LoginSysUserTokenVO> apiResult = loginService.login(loginParam);
        return apiResult;
    }
    @PostMapping("/logout")
    @OperationLogIgnore
    @ApiOperation(value = "退出", notes = "系统用户退出")
    public ApiResult<String> logout(HttpServletRequest request) throws Exception {
        loginService.logout(request);
        return ApiResult.ok("退出成功");
    }
}
